<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('商机信息')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
		<form class="layui-form head-form">
		    <div class="north">
                <th:block th:include="include :: business_btn" />
	        	<div class="layui-form layui-card-header layuiadmin-card-header-auto" style="width:calc(100%-30px)">
					<div class="layui-form-item margin_t0">
						<div th:class="'layui-inline margin_r0 '+${field.fieldFrontTopSize eq 1 ?'layui-col-sm4':(field.fieldFrontTopSize eq 2 ?'layui-col-sm8':'layui-col-sm12')}" th:each="field : ${fieldsList}"
						 th:id="${#lists.contains(oemFieldsList,field?.fields) or #lists.contains(projectFieldsList,field?.fields)?field?.fields+'_div':''}"
						 th:ftype="${#lists.contains(oemFieldsList,field?.fields)?'oemType':(#lists.contains(projectFieldsList,field?.fields)?'projectType':'')}"
						 th:style="${#lists.contains(oemFieldsList,field?.fields) and (baBusType eq '项目类型' or baBusType eq null)?'display:none':(#lists.contains(projectFieldsList,field?.fields) and (baBusType eq 'OEM类型' or baBusType eq null)?'display:none':'display:block')}">
			               	<label class="layui-form-label">
			                	<font class="f_red" th:if="${#bools.isTrue(field?.fieldFrontRequired)}">*</font>[[${field.fieldName}]]：
			              	</label>
			               	<div class="layui-input-block">
			                    <input th:if="${field.fieldFrontType} eq 't_text'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''" th:readonly="${field?.fieldFrontEdit}?'false':'true'" th:class="${field?.fieldFrontEdit}?'layui-input':'layui-input canntEdit'">
			                    <input th:if="${field.fieldFrontType} eq 't_decimal'" type="number" lay-verify="number" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:onblur="${field?.fieldFrontRequired==true}? 'inputOnBlur(this)' : ''" th:readonly="${field?.fieldFrontEdit}?'false':'true'" th:class="${field?.fieldFrontEdit}?'layui-input':'layui-input canntEdit'">
			                    <input th:if="${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" autocomplete="off" th:class="${field.fields} eq 'createTime'?'layui-input t_date canntEdit':'layui-input t_date'" readonly>
			                    	<i th:if="(${field.fieldFrontType} eq 't_date' or ${field.fieldFrontType} eq 't_datetime') and ${field.fields} neq 'createTime'" class="dhicon dh-calendar icon_date_business"></i>
						    	<input th:if="${field.fieldFrontType} eq 't_checkbox'" type="checkbox" th:checked="${field?.fieldContent == false or field?.fieldContent == null}" value="0" th:name="${field?.fields}" th:id="${field?.fields}" lay-skin="switch" th:lay-text="${field?.fields == 'bDeleted'} ? '启用|禁用' : '是|否'" th:disabled="${gridColumns.readOnly}">
							  	<input th:if="${field.fieldFrontType} eq 't_buttontext'" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" th:onclick="getMore([[${field?.fields}]],null,[[${field?.fieldName}]],[[${field?.fieldSearchType}]]);" th:getType="${field?.fields}" readonly/>
							  		<i th:if="${field.fieldFrontType} eq 't_buttontext'" class="layui-icon layui-icon-more getMore" th:onclick="getMore([[${field?.fields}]],null,[[${field?.fieldName}]],[[${field?.fieldSearchType}]]);" th:getType="${field?.fields}"></i>
								<textarea th:if="${field.fieldFrontType} eq 't_textarea'" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" th:class="${field?.fieldFrontEdit}?'layui-textarea':'layui-textarea canntEdit'" th:readonly="${field?.fieldFrontEdit}?'false':'true'">[[${field.fieldContent}]]</textarea>
								<select th:if="${field.fieldFrontType} eq 't_dropdown'" type="text" th:id="${field?.fields}" th:name="${field?.fields}" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}" lay-filter="select_top" th:data-fieldMatched="${field?.fieldMatched}" th:data-fieldFrontSave="${field?.fieldFrontSave}" th:data-fieldFrontShow="${field?.fieldFrontShow}">
									<option></option>
									<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}" th:data-vremark="${dict.vremark}"></option>
								</select>
								<input th:if="${field.fieldFrontType} eq 't_dropdownedit'" type="text" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" class="layui-input" style="position:absolute;overflow:hidden;z-index:2;width: calc(100% - 30px);" lay-verify="required" onkeyup="inputSearch()" onblur="refreshSelect()" autocomplete="off">
				               	<select th:if="${field.fieldFrontType} eq 't_dropdownedit'" th:id="${field?.fields}+'_select'" th:lay-filter="${field?.fields}+'_select'" autocomplete="off" class="layui-select" lay-search th:with="map=${field?.dropdownList}">
									<option th:each="dict : ${map}" th:text="${dict.vname}" th:value="${dict.vid}" th:selected="(${#strings.isEmpty(field.fieldContent)} and ${dict.bdefaulttext eq '是'}) or ${dict.vid.toString() eq field.fieldContent.toString()} or ${dict.vname.toString() eq field.fieldContent.toString()}"></option>
								</select>
								<input th:if="${field.fieldFrontType} eq 't_file'" type="text" class="layui-input buttontext" th:name="${field?.fields}" th:id="${field?.fields}" th:value="${field?.fieldContent}" readonly/><i th:if="${field.fieldFrontType} eq 't_file'" class="layui-icon layui-icon-upload getUpload" th:onclick="getUpload([[${field?.fields}]]);" th:getType="${field?.fields}"></i>
							</div>
			            </div>
			            <input type="hidden" th:each="fieldhide : ${fieldsHiddenList}" th:name="${fieldhide?.fields}" th:id="${fieldhide?.fields}" th:value="${fieldhide?.fieldContent}">
			     		<input type="hidden" th:each="fieldhide : ${bFieldsHiddenList}" th:name="${fieldhide?.fields}" th:id="${fieldhide?.fields}" th:value="${fieldhide?.fieldContent}">
					</div>
				</div>
	    	</div>
		    <div class="mid-content">
		        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
		    </div>
			<th:block th:include="include :: pageFooter" /> 
		</form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
var beforeDataStr = [];//定义全局参数
eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();

 	$.get("/crm/business/listbynid?nid="+nid,function(data){
 		$.each(data.data,function(k,v){
 			var beforeObj = {};
 			beforeObj['bdDate'] = v.bdDate;
 			beforeObj['guid'] = v.guid;
 			beforeDataStr.push(beforeObj);
 			dataStr.push(v);
 		});
 		initTable();//初始化表格
 	});
	toolbarEvent();//通用表格头部工具栏事件监听
	//行event事件监听
	table.on('tool(ftable)', function(obj){//表格select下拉赋值
		switch(obj.event){
	    	case 'select_baProType':
	   			tableSelected(obj, 'baProType');
	    	break;
	    	case 'select_baBusProType':
	    		tableSelected(obj, 'baBusProType');
	    	break;
    	};
	});
	monitorSort();//监听排序——重载赋值渲染
// 	$('form').children("input").onclick(function(){
// 		layer.msg('请先选择商机类型！');
// 	})
	form.on('select(select_top)', function(data){
		if(data.elem.name != 'baBusType' && !$("[name='baBusType']").val()){
			layer.msg('请先选择商机类型！');
			return false;
		}
		switch(data.elem.name){
			case 'baBusType':
				if(data.value == 'OEM类型'){
					$("div [ftype=oemType]").css('display','block');
					$("div [ftype=projectType]").css('display','none');
				}else if(data.value == '项目类型'){
					$("div [ftype=oemType]").css('display','none');
					$("div [ftype=projectType]").css('display','block');
				}else{
					$("div [ftype=oemType]").css('display','none');
					$("div [ftype=projectType]").css('display','none');
				}
				table.reload('dhtable', {
			 		height: 'full-' + ( $('.north').height()+60)
				});
			break;
			case 'baBusStep':
			    if(data.value =='Verbal'){
			        $("[name='baBusLev']").val('Jetron确定为首选');
			        $("[name='baBusLev']").attr("disabled","disabled");
			        $("[name='baBusRate']").val('90');
			    }else{
			        $("[name='baBusLev']").val('');
			        $("[name='baBusLev']").removeAttr("disabled");
			        $("[name='baBusRate']").val('');
			    }
			    form.render();
			break;
			case 'baBusLev':
				var BaBusStep_now = $("[name='baBusStep'] option:selected").val();
			    var BaBusLev_now = data.value;
			    if(BaBusStep_now=='Prospect'||BaBusStep_now=='Lost'||BaBusStep_now=='CanCel'||BaBusStep_now=='On Hold'){
			        $("[name='baBusRate']").val('0');
			    }else if(BaBusStep_now=='Goal Shared'||BaBusStep_now=='Champion'||BaBusStep_now=='Evaluation'||BaBusStep_now=='Proposal'){
			        if(BaBusLev_now=='Jetron确定为首选'){$("[name='baBusRate']").val('70');}
			        else if(BaBusLev_now=='Jetron与竞争对手平等级别'){$("[name='baBusRate']").val('50');}
			        else if(BaBusLev_now=='Jetron处于劣势'){$("[name='baBusRate']").val('30');}
			    }else if(BaBusStep_now=='Won'){
			        $("[name='baBusRate']").val('100');
			    }
			break;
		}
	});
	//切换项目类型
	function busStep(){
	    var BaBusStep_now=$("[name='BaBusStep'] option:selected").val();
	    if(BaBusStep_now=='06'){
	        $("[name='BaBusLev']").val('01');
	        $("[name='BaBusLev']").attr("disabled","disabled");
	        $("[name='BaBusRate']").val('90');
	    }else{
	        $("[name='BaBusLev']").val('');
	        $("[name='BaBusLev']").removeAttr("disabled");
	        $("[name='BaBusRate']").val('');
	    }
	}
})
function beforeSave(tableData){
	var tableData2 = [],flag = true;
	tableData3 = {};
	tableData3['nid'] = $("#nid").val();
	tableData3['productItems'] = [];
	$.each(tableData,function(v,k){
		tableData3['productItems'][v]={};
		$.each(k,function(v2,k2){
			tableData3['productItems'][v][v2] = k2;
		})
	})
	$.each(beforeDataStr,function(v,k){
		$.each(tableData3['productItems'],function(v2,k2){
			if(k.guid == k2.guid && k.bdDate != k2.bdDate){
				tableData3['productItems'][v2]['editTimes'] += 1;
				if(tableData3['productItems'][v2]['editTimes'] > 5)flag = false;
			}
		})
	})
	if(!flag){return '“预计成交日期” 修改次数不能超过 5 次';}
	tableData2.push(tableData3);
	return tableData2;
}
</script>
</body>
</html>